﻿<html>

<head>
${inc:/action/pub/common}
<title>户口明细信息</title>

</head>

<body>
<center>
<div id="divForm">
<form name="form1" onsubmit="return insertForm()" action="${def:context}${def:actionroot}/update" 
		method="POST" target="insertFrame">
<input type="hidden" name="master_tuid" value="${fld:s_tuid}">
<table width="100%" class="grid">
 <caption><font size="5"><b>动 迁 人 口 登 记 表</b></font><br/><br/></caption>
  <tr>
    <td colSpan=3>户主:<u>&nbsp;&nbsp;${fld:master_name}&nbsp;&nbsp;</u></td>
    <td colspan=3><u>&nbsp;&nbsp;${fld:cun_name}&nbsp;&nbsp;</u>街道</td>
    <td colspan=3><u>&nbsp;&nbsp;${fld:tun_name}&nbsp;&nbsp;</u>村、屯</td>
    <td colspan=3></td>
  </tr>

 <tr>
			<td class="th20">是否为<br/>坐地户</td>
			<td class="td20left" colspan="2">
	            <input name="is_local" type="radio" value="0">外来户
	            <input name="is_local" type="radio" value="1">坐地户
			</td>
			<td class="th20">离婚丧<br/>偶情况</td>
			<td class="td20left" colspan="2">
	            <input name="single_status" type="radio" value="0">无
	            <input name="single_status" type="radio" value="1">离婚
				<input name="single_status" type="radio" value="2">丧偶
			</td>
			<td class="th20">是否独<br/>生子女</td>
			<td class="td20left">
	            <input name="is_onechild" type="radio" value="0">否
	            <input name="is_onechild" type="radio" value="1">是
			</td>
			<td class="th20">安置类型</td>
			<td class="td20left" colspan="3">
	            <input name="anzhi_type" type="radio" value="0">按分户安置
	            <input name="anzhi_type" type="radio" value="1">按原房面积安置
			</td>
</tr>

  <tr>
    <th rowSpan=2>姓名</th>
    <th rowspan=2>与户主关系</th>
    <th rowspan=2>性别</td>
    <th rowspan=2>出生年月日</th>
    <th colspan=3>户口簿</th>
    <th colspan=3>结婚证</th>
    <th colspan=2 rowspan=2>备注</th>
  </tr>
  <tr align="center">
    <td>发证派出所</td>
    <td>立户时间</td>
    <td>户口编号</td>
    <td>发证机关</td>
    <td>结婚证编号</td>
    <td>登记时间</td>
  </tr>
 <tbody id="gridBody">
  <rows>
  <tr>
    <td><img src="${def:context}/images/clear.gif" onclick="deleteRow(this.parentNode.parentNode.sectionRowIndex);" border="0" class="tool" title="删除">
		<input type="text" name="user_name" size="4" value="${fld:user_name}" maxlength="30" onkeydown="changekey()"></td>
    <td><input type="hidden" name="relation_to_master" value="${fld:relation_to_master}">
		<select name="relation" onchange="selectOnchange(this)">
			<option value="">请选择</option>
			<option value="0">&nbsp;户主&nbsp;</option>
			<option value="1">&nbsp;配偶&nbsp;</option>
			<option value="2">&nbsp;长子&nbsp;</option>
			<option value="3">&nbsp;次子&nbsp;</option>
			<option value="4">&nbsp;孙子&nbsp;</option>
			<option value="5">&nbsp;外孙&nbsp;</option>
			<option value="6">&nbsp;兄弟&nbsp;</option>
			<option value="7">&nbsp;姐妹&nbsp;</option>
			<option value="8">&nbsp;长子妻&nbsp;</option>
			<option value="9">&nbsp;次子妻&nbsp;</option>
			<option value="10">&nbsp;长女&nbsp;</option>
			<option value="11">&nbsp;次女&nbsp;</option>
			<option value="12">&nbsp;女婿&nbsp;</option>
			<option value="13">&nbsp;养女&nbsp;</option>
			<option value="14">&nbsp;养子&nbsp;</option>
			<option value="15">&nbsp;母亲&nbsp;</option>
			<option value="16">&nbsp;父亲&nbsp;</option>
			<option value="17">&nbsp;孙女&nbsp;</option>
		</select>
	</td>
    <td><input type="hidden" name="user_sex" value="${fld:user_sex}">
		<select name="sex" onchange="selectOnchange(this)">
			<option value="">请选择</option>
			<option value="1">&nbsp;男&nbsp;</option>
			<option value="0">&nbsp;女&nbsp;</option>
		</select>
	</td>
    <td><input name="user_birth" type="text" size="10" maxlength="10" value="${fld:user_birth}" onkeydown="changekey()">
	</td>
    <td><input type="text" name="hukoubu_organ" size="10" value="${fld:hukoubu_organ}" maxlength="60" onkeydown="changekey()"></td>
    <td>
		<input name="hukoubu_createdate" type="text" size="6" maxlength="10" value="${fld:hukoubu_createdate}" onkeydown="changekey()">
	</td>
    <td><input type="text" name="hukoubu_id" size="10" value="${fld:hukoubu_id}" maxlength="60" onkeydown="changekey()"></td>
    <td><input type="text" name="jiehunzheng_organ" size="10" value="${fld:jiehunzheng_organ}" maxlength="60" onkeydown="changekey()"></td>
    <td><input type="text" name="jiehunzhen_id" size="10" value="${fld:jiehunzhen_id}" maxlength="30" onkeydown="changekey()"></td>
    <td>
		<input name="jiehunzheng_createdate" type="text" size="10" maxlength="10" value="${fld:jiehunzheng_createdate}" onkeydown="changekey()">
	</td>
    <td colspan=2>
		<textarea cols="10" rows="2" name="remark" onkeydown="changekey()">${fld:remark}</textarea>
		<input type="hidden" name="user_idcard" value="${fld:user_idcard}">
	</td>
  </tr>
  </rows>
  <tr>
    <td><img src="${def:context}/images/clear.gif" onclick="deleteRow(this.parentNode.parentNode.sectionRowIndex);" border="0" class="tool" title="删除">
		<input type="text" name="user_name" size="4" maxlength="30" onkeydown="changekey()"></td>
    <td><input type="hidden" name="relation_to_master" value="">
		<select name="relation" onchange="selectOnchange(this)">
			<option value="">请选择</option>
			<option value="0">&nbsp;户主&nbsp;</option>
			<option value="1">&nbsp;配偶&nbsp;</option>
			<option value="2">&nbsp;长子&nbsp;</option>
			<option value="3">&nbsp;次子&nbsp;</option>
			<option value="4">&nbsp;孙子&nbsp;</option>
			<option value="5">&nbsp;外孙&nbsp;</option>
			<option value="6">&nbsp;兄弟&nbsp;</option>
			<option value="7">&nbsp;姐妹&nbsp;</option>
			<option value="8">&nbsp;长子妻&nbsp;</option>
			<option value="9">&nbsp;次子妻&nbsp;</option>
			<option value="10">&nbsp;长女&nbsp;</option>
			<option value="11">&nbsp;次女&nbsp;</option>
			<option value="12">&nbsp;女婿&nbsp;</option>
			<option value="13">&nbsp;养女&nbsp;</option>
			<option value="14">&nbsp;养子&nbsp;</option>
			<option value="15">&nbsp;母亲&nbsp;</option>
			<option value="16">&nbsp;父亲&nbsp;</option>
			<option value="17">&nbsp;孙女&nbsp;</option>
		</select>
	</td>
    <td><input type="hidden" name="user_sex" value="">
		<select name="sex" onchange="selectOnchange(this)">
			<option value="">请选择</option>
			<option value="1">&nbsp;男&nbsp;</option>
			<option value="0">&nbsp;女&nbsp;</option>
		</select>
	</td>
    <td><input name="user_birth" type="text" size="10" maxlength="10" onkeydown="changekey()">
	</td>
    <td><input type="text" name="hukoubu_organ" size="10" maxlength="60" onkeydown="changekey()"></td>
    <td>
		<input name="hukoubu_createdate" type="text" size="6" maxlength="10" onkeydown="changekey()">
	</td>
    <td><input type="text" name="hukoubu_id" size="10" maxlength="60" onkeydown="changekey()"></td>
    <td><input type="text" name="jiehunzheng_organ" size="10" maxlength="60" onkeydown="changekey()"></td>
    <td><input type="text" name="jiehunzhen_id" size="10" maxlength="30" onkeydown="changekey()"></td>
    <td>
		<input name="jiehunzheng_createdate" type="text" size="10" maxlength="10" onkeydown="changekey()">
	</td>
    <td colspan=2>
		<textarea cols="10" rows="2" name="remark" onkeydown="changekey()"></textarea>
		<input type="hidden" name="user_idcard">
	</td>
  </tr>
  </tbody>
  <tr>
	<th colspan="12" align="center">
		<input type="submit" value="提交" class="cmd" name="submit"><input type="button" value="添加" onclick="addRow();" class="cmd" name="addBtn"><!-- <input type="button" value="返回" onclick="return gotoMaster(true);" class="cmd" name="backBtn"> --><input type="button" value="打印" onclick="return printHandler();" class="cmd" name="printBtn">
	</th>
  </tr>
</table>
</form>
<iframe name="insertFrame" style="display:none">
</iframe>
</div>
<div id="divStatus" class="alert" style="text-align:left; display:none;color:gray;width:150px;font-weight:bold;font-family:Arial">
	<img src="${def:context}/images/progress.gif"> 请稍候...
</div>
</center>

</body>

</html>

<script language="javascript">
String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

//字段校验
function insertForm(){
	if("${fld:type}" != "archives"){//如果不是历史档案的话需要校验
		if(!CheckRadio("is_local","请选择是否为坐地户","","form1")) return false;
		if(!CheckRadio("single_status","请选择离婚丧偶情况","","form1")) return false;
		if(!CheckRadio("is_onechild","请选择是否独生子女","","form1")) return false;
		if(!CheckRadio("anzhi_type","请选择安置类型","","form1")) return false;
	}
	var b = document.getElementById("gridBody");
	if(b.rows.length == 1){
		if(document.forms[0].user_name.value.Trim()==""){
			alert("姓名不能为空！");
			document.forms[0].user_name.focus();
			return false;
		}
		if(document.forms[0].relation_to_master.value.Trim()==""){
			alert("请选择与户主的关系！");
			return false;
		}
		if(document.forms[0].user_sex.value.Trim()==""){
			alert("请选择性别！");
			return false;
		}
		if(document.forms[0].user_birth.value.Trim() != ""){
			if(!CheckDate(document.forms[0].user_birth.value)){
				document.forms[0].user_birth.select();
				return false;
			}
		}
		if(document.forms[0].hukoubu_createdate.value.Trim() != ""){
			if(!CheckDate(document.forms[0].hukoubu_createdate.value)){
				document.forms[0].hukoubu_createdate.select();
				return false;
			}
		}
		if(document.forms[0].jiehunzheng_createdate.value.Trim() != ""){
			if(!CheckDate(document.forms[0].jiehunzheng_createdate.value)){
				document.forms[0].jiehunzheng_createdate.select();
				return false;
			}
		}

	}else{
		for (i=0;i<b.rows.length;i++)
		{
			if(document.forms[0].user_name[i].value.Trim()==""){
				alert("姓名不能为空！");
				document.forms[0].user_name[i].focus();
				return false;
			}
			if(document.forms[0].relation_to_master[i].value.Trim()==""){
				alert("请选择与户主的关系！");
				return false;
			}
			if(document.forms[0].user_sex[i].value.Trim()==""){
				alert("请选择性别！");
				return false;
			}
			if(document.forms[0].user_birth[i].value.Trim() != ""){
				if(!CheckDate(document.forms[0].user_birth[i].value)){
					document.forms[0].user_birth[i].select();
					return false;
				}
			}
			if(document.forms[0].hukoubu_createdate[i].value.Trim() != ""){
				if(!CheckDate(document.forms[0].hukoubu_createdate[i].value)){
					document.forms[0].hukoubu_createdate[i].select();
					return false;
				}
			}
			if(document.forms[0].jiehunzheng_createdate[i].value.Trim() != ""){
				if(!CheckDate(document.forms[0].jiehunzheng_createdate[i].value)){
					document.forms[0].jiehunzheng_createdate[i].select();
					return false;
				}
			}
		}
	}

    document.form1.submit.disabled = true;
	document.form1.addBtn.disabled = true;
	//document.form1.backBtn.disabled = true;
	document.getElementById("divStatus").style.display="";
	return true;
}

function insertOK()
{
	document.getElementById("divStatus").style.display="none";	
	document.form1.submit.disabled = false;
	document.form1.addBtn.disabled = false;
	//document.form1.backBtn.disabled = false;
	alert("保存成功.");
}

function updateError(msg)
{
	document.getElementById("divStatus").style.display="none";
	document.form1.submit.disabled = false;
	document.form1.addBtn.disabled = false;
	//document.form1.backBtn.disabled = false;
	alert(msg);
}

function addRow()
{
	var b = document.getElementById("gridBody");

	var x = b.insertRow(-1);
	
	var d = b.rows[0];

	for (i=0;i<d.cells.length;i++)
	{
		var c = x.insertCell(-1);
		c.innerHTML = d.cells[i].innerHTML;
		c.align = d.cells[i].align;
		c.valign = d.cells[i].valign;
	}
	
	document.forms[0].user_name[b.rows.length-1].value = "";
	document.forms[0].user_sex[b.rows.length-1].value = "";
	document.forms[0].sex[b.rows.length-1].options[0].selected=true;
	document.forms[0].relation_to_master[b.rows.length-1].value = "";
	document.forms[0].relation[b.rows.length-1].options[0].selected=true;
	document.forms[0].user_birth[b.rows.length-1].value = "";
	document.forms[0].hukoubu_organ[b.rows.length-1].value = "";
	document.forms[0].hukoubu_createdate[b.rows.length-1].value = "";
	document.forms[0].hukoubu_id[b.rows.length-1].value = "";
	document.forms[0].jiehunzheng_organ[b.rows.length-1].value = "";
	document.forms[0].jiehunzhen_id[b.rows.length-1].value = "";
	document.forms[0].jiehunzheng_createdate[b.rows.length-1].value = "";
	document.forms[0].remark[b.rows.length-1].value = "";
	document.forms[0].user_idcard[b.rows.length-1].value = "";

	document.forms[0].user_name[b.rows.length-1].focus();
}

function deleteRow(j)
{
	if(j==0)
	{
		alert("第一条为户主信息，不能删除！");
	}
	else
	{
		var b = document.getElementById("gridBody");
		b.deleteRow(j);
	}
}

function selectOnchange(obj){
	obj.parentNode.childNodes[0].value = obj.value;
}

window.onload = function(){
	var b = document.getElementById("gridBody");
	var length = b.rows.length;
	if(length > 1){
		deleteRow(length-1);
		if(b.rows.length == 1){
			var val = document.forms[0].relation_to_master.value;
			for(i=0;i<document.forms[0].relation.options.length;i++){
				if(val == document.forms[0].relation.options[i].value){
					document.forms[0].relation.options[i].selected = true;
					break;
				}
			}

			var val2 = document.forms[0].user_sex.value;
			for(i=0;i<document.forms[0].sex.options.length;i++){
				if(val2 == document.forms[0].sex.options[i].value){
					document.forms[0].sex.options[i].selected = true;
					break;
				}
			}
		}else{
			for (j=0;j<b.rows.length;j++)
			{
				var val = document.forms[0].relation_to_master[j].value;
				for(i=0;i<document.forms[0].relation[j].options.length;i++){
					if(val == document.forms[0].relation[j].options[i].value){
						document.forms[0].relation[j].options[i].selected = true;
						break;
					}
				}

				var val2 = document.forms[0].user_sex[j].value;
				for(i=0;i<document.forms[0].sex[j].options.length;i++){
					if(val2 == document.forms[0].sex[j].options[i].value){
						document.forms[0].sex[j].options[i].selected = true;
						break;
					}
				}
			}
		}
	}
}

function gotoMaster(flag){
	var url = "";
	if("${fld:type}" == "archives"){
		url = "${def:context}/action/dq/archives/history/crud";
	}else{
		url = "${def:context}/action/dq/yewu/liangfang/crud";
	}
	if(flag == true){
		if(window.confirm("确定放弃修改？") == true){
			document.location.href = url;
		}
	}else{
		document.location.href = url;
	}
	
}

function printHandler(){
	var url = "${def:context}${def:actionroot}/print?id=${fld:s_tuid}&random="+Math.random();
	var titleString = "hukou";
	var ScWidth = screen.availwidth - 10;
	var ScHeight = screen.availheight - 48;
	var WindowOption = "location=no,menubar=yes,toolbar=no,scrollbars=yes,status=yes,resizable=yes,top=0,left=0";
	WindowOption = WindowOption + ",width=" + ScWidth;
	WindowOption = WindowOption + ",height=" + ScHeight;
	var newWin = window.open(url, titleString, WindowOption);
	newWin.focus();
}


function changekey(evt){
	evt = (evt) ? evt : ((window.event) ? window.event : "") //兼容IE和Firefox获得keyBoardEvent对象
  var keycode = evt.keyCode?evt.keyCode:evt.which; //兼容IE和Firefox获得keyBoardEvent对象的键值	
	
	if(keycode != 37 && keycode != 38 && keycode != 39 && keycode != 40)   
		return   true; 

	var actEle=document.activeElement;	
  if(!actEle) {document.getElementsByTagName("input")[0].focus();   return;}  
  var allEles = document.getElementsByTagName("*");
	
  var actIndex=actEle.sourceIndex; 
	if(!actIndex){
	  for(var i=0;i<allEles.length;i++){//兼容FF
	  	if(allEles[i].name==actEle.name)
	  	actIndex = i;
	  }
	}
  

	if(keycode == 37 || keycode == 38){
	  for(var i = actIndex-1;i>=0;i--){

	  	if(Test(allEles[i].tagName) && allEles[i].readOnly == false && allEles[i].type !="hidden"){  
	  		//window.event.returnValue=false;
	  		allEles[i].focus();
	  		return   false;
	  	}
	  }
	}

	if(keycode == 39 || keycode == 40){
	  for(var i=actIndex+1;i<allEles.length;i++){
	  	if(Test(allEles[i].tagName) && allEles[i].readOnly == false && allEles[i].type !="hidden"){

				//window.event.returnValue=false;
	  		allEles[i].focus();
	  		return   false;
	  	}
	  }
	}

  return   false;   
}

  function   Test(tag){  
  var   regTag="INPUT|SELECT|TEXTAREA|BUTTON|RADIO";//可以在这里添加需要获得焦点的对象的tagname  
  var   tags = regTag.split("|");  
  for(var i=0;i<tags.length;i++){
  	if(tag==tags[i])  
  		return   true;  
  }
  return   false;  
  }
</script>
    